Quarto is a stunning tool. It transforms your R or Python code in a very clean report that includes code, charts, explanation and everything else you would like to include. Lumo is a quarto template. It slightly modifies the default appearance of a Quarto document, to make it even more shiny, and fit your brand. This document demoes how a document made with lumo looks like, list its main features and explain how to use it in 3 minutes.
Author: Holtz Yan
Date: September 10, 2024
Introduction
Quarto is probably my favorite tool in the R/Python universe. Transforming your code and thoughts into a stunning report in one click always blows my mind.
Even if the default appearance looks good, there are a few tweaks I always like to apply to push the report to the next level.
Btw, you can learn how to master Quarto thanks to my online course: Productive R Workflow
This document aims at showcasing how a quarto document made with the lumo format looks like.
this package provides my favorite ggplot2 theme: theme_ipsum()
2
because I was too lazy to find something better in the R Color Finder!
By the way, you should open the code chunk that is folded above. ⬆️ There is a little stunning surprise on its right hand side.
Everybody loves map ❤️
Don’t forget that you can add full width content, which can be very useful for instance for a nice interactive map made with leaflet.
Code
# Load the library.library(leaflet)# Make a mapleaflet() %>%addTiles() %>%# Add default OpenStreetMap map tilesaddMarkers(lng =174.768, lat =-36.852, popup ="The birthplace of R")
Connecting graphs
All right, many people know how to create interactive graphs with plotly. But did you know that you can connect graphs together thanks to ggiraph? And using a syntax pretty close from ggplot2?
Pretty close from dark magic isn’t.
Code
# Read the full world mapworld_sf <-read_sf("https://raw.githubusercontent.com/holtzy/R-graph-gallery/master/DATA/world.geojson")world_sf <- world_sf %>%filter(!name %in%c("Antarctica", "Greenland"))# Create a sample datasethappiness_data <-data.frame(Country =c("France", "Germany", "United Kingdom","Japan", "China", "Vietnam","United States of America", "Canada", "Mexico" ),Continent =c("Europe", "Europe", "Europe","Asia", "Asia", "Asia","North America", "North America", "North America" ),Happiness_Score =rnorm(mean =30, sd =20, n =9),GDP_per_capita =rnorm(mean =30, sd =20, n =9),Social_support =rnorm(mean =30, sd =20, n =9),Healthy_life_expectancy =rnorm(mean =30, sd =20, n =9))# Join the happiness data with the full world mapworld_sf <- world_sf %>%left_join(happiness_data, by =c("name"="Country"))# Create the first chart (Scatter plot)p1 <-ggplot(world_sf, aes( GDP_per_capita, Happiness_Score,tooltip = name,data_id = Continent,color = Continent)) +geom_point_interactive(data =filter(world_sf, !is.na(Happiness_Score)), size =4) +theme_minimal() +theme(axis.title.x =element_blank(),axis.title.y =element_blank(),legend.position ="none" )# Create the second chart (Bar plot)p2 <-ggplot(world_sf, aes(x =reorder(name, Happiness_Score),y = Happiness_Score,tooltip = name,data_id = Continent,fill = Continent)) +geom_col_interactive(data =filter(world_sf, !is.na(Happiness_Score))) +coord_flip() +theme_minimal() +theme(axis.title.x =element_blank(),axis.title.y =element_blank(),legend.position ="none" )# Create the third chart (choropleth)p3 <-ggplot() +geom_sf(data = world_sf, fill ="lightgrey", color ="lightgrey") +geom_sf_interactive(data =filter(world_sf, !is.na(Happiness_Score)),aes(fill = Continent, tooltip = name, data_id = Continent) ) +coord_sf(crs =st_crs(3857)) +theme_void() +theme(axis.title.x =element_blank(),axis.title.y =element_blank(),legend.position ="none" )# Combine the plotscombined_plot <- (p1 + p2) / p3 +plot_layout(heights =c(1, 2))# Create the interactive plotinteractive_plot <-girafe(ggobj = combined_plot)interactive_plot <-girafe_options( interactive_plot,opts_hover(css ="fill:red;stroke:black;"))interactive_plot
Figure: three graphs connected thanks to ggiraph
Interactive table
It is very easy to insert an interactive table in your document thanks to the DT package. The output allows to filter rows, search for something and sort using a specific columns!
Install the library with install.packages("DT"). Then, just pass a dataframe to the datatable() function to get a stunning interactive output!
Code
library(DT)data(iris)# Make a tabledatatable(iris, filter ="top")
A grey section
It’s always good to have a grey section. Makes the document breath a bit.
You can also make a boxplot, but please do not hide the underlying distribution! This is widely explain in my data-to-viz.com project in case you’re not convinced 😋.
When you make a Quarto doc, it is a good practice to include information about your working environment. This is straightforward, you just have to call the sessionInfo() info and all your R and package versions will be printed. This is a huge boost for reproducibility.